#include <cstdio>

using namespace std;

const int maxn=50;

int main() {
    freopen("bondorudo.in", "r", stdin);
    freopen("bondorudo.out", "w", stdout);

    static bool map[maxn+1][maxn+1];
    static int deg[maxn+1];
    int n, m;
    scanf("%d %d", &n, &m);
    printf("%d\n", m==n-1 ? 1 : (m*2<3*n ? 2 : 3));
    for (int i=1; i<=m; i++) {
        if (i<=n-1) {
            printf("%d %d\n", i, i+1);
            deg[i]++, deg[i+1]++;
            map[i][i+1] = map[i+1][i] = true;
        } else if (i==n) {
            printf("%d %d\n", n, 1);
            deg[n]++, deg[1]++;
            map[1][n] = map[n][1] = true;
        } else {
            bool flag=false;
            for (int j=1; j<=n; j++) {
                int nj=(j+n/2-1)%n+1;
                if (!map[j][nj] && deg[nj]<=2*m/n && deg[j]<=2*m/n) {
                    printf("%d %d\n", j, nj);
                    map[j][nj] = map[nj][j] = true;
                    deg[nj]++, deg[j]++;
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                for (int x=1; x<=n && !flag; x++) {
                    for (int y=x+1; y<=n && !flag; y++) {
                        if (!map[x][y]) {
                            printf("%d %d\n", x, y);
                            map[x][y] = map[y][x] = true;
                            flag = true;
                            break;
                        }
                    }
                }
            }
        }
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
